<?php 
//商品的添加
error_reporting(E_ALL^E_NOTICE^E_WARNING);
date_default_timezone_set("PRC");
	include_once("./com.php");
	$rem="select * from product";
  	$ser=mysql_query($rem);
  	//随机数
  	 $a="tk_";
 	 $b=date("Ymd");
 	 $c=rand(10000,99);
 	 $ane=$a.$b.$c;

 	 if(isset($_POST['sub'])){
 	 	$pname = $_POST['pname'];
 	 	$pc_cid = $_POST['pc_cid'];
 	 	$price = $_POST['price'];
 	 	$sprice = $_POST['sprice'];
 	 	$addr = $_POST['addr'];
 	 	$keyword = $_POST['keyword'];
 	 	$pnums = $_POST['pnums'];
 	 	$snums = $_POST['snums'];
 	 	$ifshow = $_POST['ifshow'];
 	 	$color = implode("-",$_POST['color']);
 	 	$size = implode("-",$_POST['size']);
 	 	//单文件上传成功
 	 	$pimg = $_FILES['pimg']['name'];
 	 	$pimgg = $_FILES['pimg']['tmp_name'];
 	 	$pathp="../uploads";
 	 	move_uploaded_file($pimg,$pathp."/".$pimgg);
			//多文件上传
 	 	$pimgs = $_FILES['pimgs'];
 		$pimg_str = implode("-",$pimgs['name']);
 		$pimgsimg = count($pimgs);
 		$path = "../uploads";
 		for($a = 0;$a < $pimgsimg;$a++){
 			$p_img = $pimgs['name'][$a];
 			$tmp = $pimgs['tmp_name'][$a];
 			move_uploaded_file($tmp,$path."/".$p_img);
 		};
 			
 	 	$descp = strip_tags($_POST['descp']);
 	 	$res = "insert  into product(pname,price,sprice,addr,keyword,pnums,snums,ifshow,color,size,pimg,pimgs,descp,pc_cid)values('$pname','$price','$sprice','$addr','$keyword','$pnums','$snums','$ifshow','$color','$size','$pimg','$pimg_str','$descp','$pc_cid')";
 	 	mysql_query($res);
 	 	if(mysql_affected_rows()>0){
 	 		echo"<script>
				alert('添加成功')
				location.href='product.php'
				</script>";
 	 	}else{
 	 		echo"<script>
				alert('添加失败')
				location.href='product_add.php'
				</script>";
 	 	}
 	 };
 	 

$set = "select * from pc_fenlei";
	$res = mysql_query($set);
	while($list = mysql_fetch_assoc($res)){
	$sets[] = $list;
	};

	function arrav($sets,$fid=0){
		static $arr_arr=array();
		foreach($sets as $key=>$value){
			if($value['pc_fid']==$fid){
				$arr_arr[]=$value;
				arrav($sets,$value['pc_cid']);
			}
		}
		return $arr_arr;
	}
	$arr_arr=arrav($sets);

 ?>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主体部分</title>
<base target="_self">
<link rel="stylesheet" type="text/css" href="skin/css/base.css" />
<link rel="stylesheet" type="text/css" href="skin/css/main.css" />
<style>
	.c1{
		width:20px;
		height:20px;
		background:red;
		display:inline-block;
	}
	.c2{
		width:20px;
		height:20px;
		background:green;
		display:inline-block;
	}
	.c3{
		width:20px;
		height:20px;
		background:blue;
		display:inline-block;
	}


</style>
</head>
<body leftmargin="8" topmargin='8'>
<table width="98%" align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#CBD8AC" style="margin-bottom:8px;margin-top:8px;">
  <tr>
    <td background="skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' colspan="2"><span><img src='skin/images/frame/arr3.gif' style='margin-right:10px;'>添加商品</span></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>
		<table style="margin-bottom:8px;margin-top:8px;margin-left:20px;">
			<form  action="" method="post" enctype="multipart/form-data">
			<tr>
				<td width="100px;">商品名称:</td>
				 <td><input type="text" name="pname" value="" id="d1">
				 	<span id="span1"></span>
				 </td>
			</tr>	
			<tr> 
				<td>商品分类:</td>
				<td>
					<select name="pc_cid">
					<?php foreach ($arr_arr as $value) { ?>
					<option value="<?= $value['pc_cid'] ?>">
					<?= str_repeat("&nbsp;",($value['pc_level']-1)*9).$value['pc_name']?>
					</option>
				<?php } ?>
					</select>
				</td>
			</tr>  
			<tr>
				 <td>产品价格：</td>
				 <td><input type="text" name="price" value=""></td>
			</tr> 
			<tr>
				 <td>优惠价格：</td>
				 <td><input type="text" name="sprice" value=""></td>
			</tr>  
			<tr>
				 <td>产地：</td>
				 <td><input type="text" name="addr" value=""></td>
			</tr>  
			<tr>
				 <td>关键字：</td>
				 <td><input type="text" name="keyword" value=""></td>
			</tr> 
			<tr>
				 <td>产品序列号：</td>
				 <td><input type="text" name="pnums" value="<?= $ane ?>"></td>
			</tr> 
			<tr>
				 <td>库存：</td>
				 <td><input type="text" name="snums" value=""></td>
			</tr>  
			<tr>
				 <td>是否展示：</td>
				 <td><input type="radio" name="ifshow" value="1" checked>展示
				 	<input type="radio" name="ifshow" value="2">不展示
				 </td>
			</tr> 
			<tr>
				 <td>颜色：</td>
				 <td>
				<input type="checkbox" name="color[]" value="red"><div class="c1"></div>
				<input type="checkbox" name="color[]" value="green"><div class="c2"></div>
				<input type="checkbox" name="color[]" value="blue"><div class="c3"></div></td>	
			<tr>
			<tr>
				 <td>尺寸 ：</td>
				<td>
				<input type="checkbox" name="size[]" value="L">L
				<input type="checkbox" name="size[]" value="XL">XL
				<input type="checkbox" name="size[]" value="XXL">XXL
				<input type="checkbox" name="size[]" value="XXXL">XXXL
				</td>	
			</tr>
			<tr>
				 <td>标题图片</td>
				<td>
				<input type="file" name="pimg" value="">
				</td>	
			</tr>
			<tr>
				 <td>图片库</td>
				<td>
				<input type="file" name="pimgs[]" value="" multiple>
				</td>	
			</tr>
			<tr>
				<td>产品描述：</td>
				<td>
				<?php
				include_once("./fckeditor/fckeditor.php");
				$fckeditor = new FCKeditor("descp");//定义默认值 name
				$fckeditor->Width = "300px";//定义编辑器的宽度
				$fckeditor->Height = "200px";//定义编辑器的高度
				$fckeditor->Value = "";//定义默认值
				$fckeditor->BasePath='./fckeditor/';
				$fckeditor->ToolbarSet = "Basic";
				$fckeditor->Create();//创建编辑器
				?>
				</td>
				<tr>
				 <td colspan="2" align="center" height="40px">
				 	<input type="submit" name="sub" value=" 添加 " class="coolbt2"></td>
			   </tr>
			</tr>
		</form>
		</table>
	</td>
  </tr>
</table>
<!-- <script type="text/javascript">
			name1=document.getElementById("d1");
			span2=document.getElementById("span1");
				name1.onblur=function(){
					bank=name1.value
					preg=/^\w{6,12}$/
					if(preg.test(bank)){
						span2.innerHTML="√";
						span2.style.color="green";	
					}else{
						span2.innerHTML="*";
						span2.style.color="red";
					}
				}
				name1.onfocus=function(){
					span2.innerHTML="";
				}



</script> -->
</body>
</html>